package com.tang.framework.config.pay.ali;


import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.AlipayConfig;
import com.alipay.api.DefaultAlipayClient;

import com.tang.common.properties.AliPayConfigProperties;
import com.tang.common.properties.sys.CoolTeaProperties;
import com.tang.framework.core.cache.CoolTeaConfig;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

import jakarta.annotation.PostConstruct;

/**
 * @author tang jun liang
 * @Date 2023/6/25 16:56
 */
@SpringBootConfiguration
@ConditionalOnProperty(prefix = "cool-tea", name = "ali-pay", havingValue = "true")
public class AliPayConfig {



    @Bean
    public AlipayClient alipayClient() throws AlipayApiException {
        AliPayConfigProperties aliPayConfigProperties = CoolTeaConfig.getConfig(AliPayConfigProperties.class);
        AlipayConfig config = new AlipayConfig();
        config.setAppId(aliPayConfigProperties.getAppId());
        config.setPrivateKey(aliPayConfigProperties.getPrivatekey());
        config.setSignType(aliPayConfigProperties.getSignType());
        config.setAlipayPublicKey(aliPayConfigProperties.getAlipayPublicKey());
        return new DefaultAlipayClient(config);
    }
}
